<!-- 主修课成绩管理 -->
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
		<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
		<link rel="stylesheet" href="/css/font.css">
		<link rel="stylesheet" href="/css/xadmin.css">
	</head>

	<body>
		<div class="x-body" id="app">
			<input type="hidden" th:attr="classId=${classId}" id="input_classId"/>
			<input type="hidden" th:attr="courseNo=${courseNo}" id="input_courseNo"/>
			<input type="hidden" th:attr="tchCourseId=${tchCourseId}" id="input_tchCourseId"/>
			<a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);"
	              title="刷新"><i class="layui-icon" style="line-height:30px">ဂ</i></a>
			<span class="x-right" style="line-height:40px;float:left">共有数据：{{ pageInfo.total }} 条，当前{{ pageInfo.pageNum }} / {{ pageInfo.pages }}页</span>
			<table class="layui-table">
				<thead>
					<tr>
						<th width="100">学号</th>
						<th width="100">姓名</th>
						<th width="100">性别</th>
						<th width="100">成绩</th>
						<th width="100">操作</th>
				</thead>
				<tbody>
					<tr v-for="stuScore in stuScores">
                        <td>{{ stuScore.stuNo }}</td>
                        <td>{{ stuScore.stuName }}</td>
                        <td v-if="stuScore.stuSex == 2">男</td>
                        <td v-else-if="stuScore.stuSex == 1">女</td>
                        <td>{{ stuScore.score }}</td>
                        <td class="td-manage">
                            <button class="layui-btn-normal layui-btn layui-btn-sm" onclick="editStuScore(this)" :data-stuNo="stuScore.stuNo" :data-stuName="stuScore.stuName" :data-id="stuScore.id" :data-score="stuScore.score" href="javascript:;"><i
                                 class="layui-icon">&#xe705;</i>编辑成绩</button>
                        </td>
                    </tr>
				</tbody>
			</table>
			<div class="page" style="margin-top: 10px !important;">
               <div>
                 <a class="prev pageTxt" href="javascript:void(0)">上一页</a>
                 <a class="first pageTxt" href="javascript:void(0)">首页</a>
                 <template v-for="pageNum in pageInfo.navigatepageNums">
                     <a class="num" href="javascript:void(0)" v-if="pageInfo.pageNum != pageNum" :data="pageNum">{{ pageNum }}</a>
                     <span class="current" v-else :data="pageNum">{{ pageNum }}</span>
                 </template>
                 <a class="last pageTxt" href="javascript:void(0)">尾页</a>
                 <a class="next pageTxt" href="javascript:void(0)">下一页</a>
               </div>
             </div>
		</div>
		<script type="text/javascript" src="/js/jquery.min.js"></script>
        <script type="text/javascript" src="/js/xadmin.js"></script>
        <script type="text/javascript" src="/lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="/js/vue.min.js"></script>
        <script type="text/javascript" src="/js/jquery.form.js"></script>
		<script>
			var vm = new Vue({
	            el : '#app',
	            data : {
	                // 当前班级的学生列表
	                stuScores : "",
	                pageInfo:"",
	                // 当前班级id
	                classId : "",
	                // 当前课程代码
	                courseNo : "",
	                // 当前教师课程id
	                tchCourseId: ""
	            },
	            created : function() {
	                this.classId = $("#input_classId").attr("classId");
	                this.courseNo = $("#input_courseNo").attr("courseNo");
	                this.tchCourseId = $("#input_tchCourseId").attr("tchCourseId");
	                // 获取当前班级的学生列表
	                this.listStuScoreByClassId(this.classId, this.courseNo, 1);
	            },
	            methods : {
	            	listStuScoreByClassId : function(classId, courseNo, pageNum) {
	                    var vm = this;
	                    $.ajax({
	                        url : "/teacher/score/listStuScore",
	                        data: {
	                        	classId: classId,
	                        	courseNo: courseNo,
	                        	pageNum: pageNum
	                        },
	                        type : "get",
	                        success : function(result) {
	                            if (result.state) {
	                                vm.pageInfo = result.data;
	                                vm.stuScores = result.data.list;
	                            } else {
	                                layui.use(['layer'], function(){
	                                    var layer = layui.layer
	                                    layer.msg(""+result.msg, {icon: 5});
	                                });
	                            }
	                        }
	                    });
	                }
	            }
	        });
			// 编辑成绩
            function editStuScore(obj) {
				var stuName = $(obj).attr("data-stuName");
				var stuNo = $(obj).attr("data-stuNo");
				var id = $(obj).attr("data-id");
				var score = $(obj).attr("data-score");
            	layer.open({
                    type: 1, //Page层类型
                    btn: ["确定", "取消"],
                    title: '编辑成绩',
                    skin: 'layui-layer-prompt',
                    content: "<input type='text' class='layui-layer-input' disabled value='"+ stuName +"'><br><input type='number' class='layui-layer-input' value='"+score+"' placeholder='课程成绩'>",
                    yes: function(index, layero) {
                        // 按钮【按钮一】的回调
                        var score = $(layero).find("input[type='number']").val();
                        // 数据检验
                        if (score <= 0 || score > 100) {
                            layer.msg('请输入正确的课程成绩', {
                                icon: 5,
                                time: 1000
                            });
                            return;
                        }
                        // 保存
                        $.ajax({
                            url: "/teacher/score/saveStuScore",
                            data: {
                            	id: id,
                            	tchCourseId: vm.tchCourseId,
                                stuNo: stuNo,
                                courseType: 1,
                                courseNo: vm.courseNo,
                                score: score
                            },
                            type: "post",
                            success: function(result) {
                                if (result.state) {
                                    layer.msg("编辑成功", {
                                        icon: 1
                                    });
                                    vm.listStuScoreByClassId(vm.classId, vm.courseNo, vm.pageInfo.pageNum);
                                    // 关闭
                                    layer.close(index);
                                } else {
                                    layer.msg("" + result.msg, {
                                        icon: 5
                                    });
                                }
                            }
                        });
                    }
                })
            }
			
			// 点击页码数，进行跳转
            $(".page").delegate(".num", "click", function() {
                var pageNum = $(this).attr("data");
                vm.listStuScoreByClassId(vm.classId, vm.courseNo, pageNum);
            });
            // 上一页
            $(".page").delegate(".prev", "click", function() {
                if (vm.pageInfo.hasPreviousPage) {
                    vm.listStuScoreByClassId(vm.classId, vm.courseNo, vm.pageInfo.pageNum - 1);
                }
            });
            // 下一页
            $(".page").delegate(".next", "click", function() {
                if (vm.pageInfo.hasNextPage) {
                    vm.listStuScoreByClassId(vm.classId, vm.courseNo, vm.pageInfo.pageNum + 1);
                }
            });
            // 首页
            $(".page").delegate(".first", "click", function() {
                if (!vm.pageInfo.isFirstPage) {
                    vm.listStuScoreByClassId(vm.classId, vm.courseNo, 1);
                }
            });
            // 尾页
            $(".page").delegate(".last", "click", function() {
                if (!vm.pageInfo.isLastPage) {
                    vm.listStuScoreByClassId(vm.classId, vm.courseNo, vm.pageInfo.pages);
                }
            });
		  
		</script>
	</body>

</html>
